package com.example.demo1.repository;

import com.example.demo1.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;



public interface CommentRepository extends JpaRepository<Comment,Integer> {

//    public List<Comment> findAllByAIdAndAndAuthor();


//    @Query("SELECT c FROM t_comment c WHERE c.aId = ?1")
//    public List<Comment> selectCommentByArticleId1(Integer id);

    @Query(value = "select * from t_comment c where c.a_id=?1",nativeQuery = true)
    public List<Comment> selectCommentByArticleId2(Integer id);

    @Transactional
    @Modifying
    @Query(value="insert into t_comment(author,content,a_id) values(?1,?2,?3)",nativeQuery=true)
    public int addComment(String author,String content,Integer aId);
}
